package com.etrans.web.gps.util;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 报警类型工具类
 * 用来接收配置文件上定义的报警类型
 * @author jw.chen
 *
 */
public class AlarmKindUtil {
	
	private String alarmStr;
	
	private String staticAnormalStr;
	
	public String getStaticAnormalStr() {
		return staticAnormalStr;
	}

	public void setStaticAnormalStr(String staticAnormalStr) {
		this.staticAnormalStr = staticAnormalStr;
	}

	public String getAlarmStr() {
		return alarmStr;
	}

	public void setAlarmStr(String alarmStr) {
		this.alarmStr = alarmStr;
	}
	
	public Set<Integer> getAlarmKindSet(){
		String[] strs = alarmStr.split(",");
		Set<Integer> set = new HashSet<Integer>(strs.length);
		for(String str : strs){
			try{
				set.add(Integer.parseInt(str));
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		return set;
	}
	
	public Set<Integer> staticAnormalStr(){
		String[] strs = staticAnormalStr.split(",");
		Set<Integer> set = new HashSet<Integer>(strs.length);
		for(String str : strs){
			try{
				set.add(Integer.parseInt(str));
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		return set;
	}
	public List<Integer> getAlarmKindList(){
		String[] strs = alarmStr.split(",");
		List<Integer> list = new ArrayList<>();
		for(String str : strs){
			try{
				list.add(Integer.parseInt(str));
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		return list;
	}
	public Integer[] getAlarmKindInt(){
		String[] strs = alarmStr.split(",");
		Integer[] alarmKind = new Integer[strs.length];
		for(int i = 0; i < strs.length; i++){
			alarmKind[i] = Integer.parseInt(strs[i]);
		}
		return alarmKind;
	}
	
	/**
	 * mongo统计表字段对应的报警类型
	 * @param alarmName
	 * @return
	 */
	public Integer getAlarmKind(String alarmName){
		if("overspeed".equals(alarmName)){				//超速报警
			return 1;		
		}else if("roadoffset".equals(alarmName)){		//偏离路线报警
			return 11;		
		}else if("tired".equals(alarmName)){			//疲劳驾驶报警
			return 2;								
		}else if("nightly_3rd".equals(alarmName)){		//夜间三级路面报警
			return 15;		
		}else if("prohibit_driving".equals(alarmName)){	//2-5点禁行报警
			return 14;		
		}else{
			return null;
		}
	}
	
	/**
	 * mongo统计表字段对应的报警类型
	 * @param alarmName
	 * @return
	 */
	public String getAlarmKindName(Integer alarmType){
		if(alarmType == 1){
			return "超速";
		}else if(alarmType == 11){
			return "路线偏离";
		}else if(alarmType == 2){
			return "疲劳驾驶";
		}else if(alarmType == 15){
			return "夜间三级路面";
		}else if(alarmType == 14){
			return "2-5点禁行";
		}else{
			return "";
		}
	}
}
